package com.googlecode.gwtbb.client.only.widget.display.picture;

import com.google.gwt.user.client.ui.*;
import com.googlecode.gwtbb.client.shared.entity.picture.Picture;

import java.util.List;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Feb 5, 2009
 */
public class ThumbRow extends Composite {
	private HorizontalPanel mainPanel;
	private List<Picture> pictures;

	public ThumbRow() {
		mainPanel = new HorizontalPanel();
		initWidget(mainPanel);
	}

	public List<Picture> getPictures() {
		return pictures;
	}

	public void clear() {
		setPictures(null);
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
		mainPanel.clear();
		if (pictures != null)
			for (final Picture picture : pictures) {
				FocusPanel focusPanel = new FocusPanel();
				mainPanel.add(focusPanel);
				focusPanel.setStylePrimaryName("gwtbb-Hypolink");
				focusPanel.setWidget(new TooltipThumb(picture));
				focusPanel.addClickListener(new ClickListener() {
					public void onClick(Widget sender) {
						PopupPanel popup = new PopupPanel(true);
						popup.setAnimationEnabled(false);
						DecoratorPanel decorator = new DecoratorPanel();
						popup.setWidget(decorator);
						decorator.setStylePrimaryName("gwtbb-grayFeathered-decorator");

						VerticalPanel panel = new VerticalPanel();
						decorator.setWidget(panel);
						Picture.Info info = picture.getInfo();
						if (info != null)
							panel.add(new PropImage(info.getLargeThumb()));
						panel.add(new Label(picture.getCaption()));
						popup.center();
					}
				});
			}
	}
}
